import { BrowserRouter, Switch, Route, Redirect, RouteComponentProps } from 'react-router-dom'
import Layout from '../pages/layout/Layout';
import Login from '../pages/login/Login';
import NoPage from '../pages/404'

const Router = () => {
    return (
        <BrowserRouter>
            <Switch>
                <Route path="/login" render={props => (
                    sessionStorage.getItem('token') ? <Redirect to='/' /> : <Login {...props} />
                )}></Route>
                <Route exact path="/404" component={NoPage}></Route>
                <Route path="/" render={() => (sessionStorage.getItem('token') ? <Layout /> : <Redirect to="/login" />)}></Route>
                <Route path="*" render={() => <Redirect to="/404"/>}></Route>
            </Switch>
        </BrowserRouter>
    );
};

export default Router;